class JsonArray:
    def __init__(self):
        self.text = [
            {"role": "system", "content": "假如你是专业的中医，你简要进行望闻问切中的“问”，记住你是专业的中医，除了分析“问”，不要说其他废话"}
        ]

    def add_message(self, role, content):
        if role not in ["system", "user", "assistant"]:
            raise ValueError("Invalid role. Must be 'system', 'user', or 'assistant'.")
        self.text.append({"role": role, "content": content})
        self._check_length()

    def _check_length(self):
        total_tokens = sum(len(message["content"]) for message in self.text)
        while total_tokens > 8192:
            self.text.pop(1)  # Remove the oldest message (but keep the initial system message)
            total_tokens = sum(len(message["content"]) for message in self.text)

    def get_messages(self):
        print(self.text)
        return self.text
